package com.swt.dao.impl.S_impl;

import com.swt.dao.S_dao.GetUserDao;
import com.swt.domain.Image;
import com.swt.domain.User;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class GetUserDaoImpl implements GetUserDao {
    @Resource
    private HibernateTemplate hibernateTemplate;

    /**
     * 通过userID获取user
     * */
    public User getUserById(int id){
        return hibernateTemplate.get(User.class,id);
    }

    /**
     * 获取轮播图
     * */
    public List<Image> getImage(){
        Session session=hibernateTemplate.getSessionFactory().getCurrentSession();
        Query query=session.createQuery("from Image where imageStatus='已发布'");
        List<Image>list=query.list();
        return list;
    }

}
